package us.wili.dev.third.util.example.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * author: lefore
 * date: 2018/9/30
 */
@Configuration
@EnableConfigurationProperties(WxpayConfig.WxpayPropertiesCreator.class)
public class WxpayConfig {

    @Bean
    public WxPayService wxPayService(WxpayPropertiesCreator propCreator) {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(propCreator.getWxpay());
        return wxPayService;
    }

    @ConfigurationProperties
    public static class WxpayPropertiesCreator {

        private WxPayConfig wxpay;

        public WxPayConfig getWxpay() {
            return wxpay;
        }

        public void setWxpay(WxPayConfig wxpay) {
            this.wxpay = wxpay;
        }
    }
}
